import java.sql.*;

/**
 * @BelongsProject: SSM
 * @Author: cmy
 * @CreateTime: 2023-01-13  21:36
 * @Description: TODO
 */

public class JDBC_Conn {

    public void getConn(){
        try {
            Class.forName("");
            Connection connection = DriverManager.getConnection("", "", "");

            String sql = "insert into t_user values()";
            PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS );
            ps.executeUpdate();

            // TODO 获取：当前插入条目，的“主键”
            ResultSet generatedKeys = ps.getGeneratedKeys();    // 单行单列
            generatedKeys.next();
            int id = generatedKeys.getInt(1);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
    }
}
